function loanDetail(data){
	$("#sjxqdt .xf_zjxq img").attr("src","images/default1.jpg");
	$("#sjxqdt .xf_zjxq img").attr("isbn",data.attr("isbn"));
	coverCover();
	$("#sjxqdt .xf_zjxq ul p").html(data.attr("title"));
	$("#sjxqdt .xf_zjxq ul span").html(data.attr("author"));
	
	$("#otherTitle").html("书名："+data.attr("title"));
	$("#otherAuthor").html("作者："+data.attr("author"));
	$("#otherPublisher").html("出版社："+data.attr("publisher"));
	$("#otherIsbn").html("isbn："+data.attr("isbn"));
	$("#otherClass").html("类型："+data.attr("class0"));
	
	setSumary(data.attr("isbn"));
	
}

function toMyLoan(userid){
	$.ajax({
		url :interfaceMobileUrl+"/myLoan.json?userid="+userid+"&key="+userkey,
		jsonp: "callback",
	    dataType: "jsonp",
		beforeSend:function(data){
			$("#myLoanUl").html("");
			$("#myLoanUl").append(getLoadingLi("正在加载中..."));
		},
		error:function(data){
			$("#myLoanUl").html("");
			$("#myLoanUl").append(getNoneDataLi("网络连接失败..."));
		},
		success:function(data){
			var loans = eval('(' + data + ')');
			loans = loans.list[0]["com.opac.readerHome.domain.Loan"];
			$("#myLoanUl").html("");
			if(loans == undefined){
				$("#myLoanUl").append(getNoneDataLi("未获取到您借阅的书籍"));
				return ;
			}
			if(loans.length==undefined){
				loans = [loans];
			}
			for(var i = 0;i<loans.length;i++){
				var title = loans[i].title;
				var author = loans[i].author;
				if(author !=undefined){
					author =  author.replace('著','');
				}
				var isbn = loans[i].isbn;
				var gLibcode = loans[i].gLibcode;
				var barcode = loans[i].barcode;
				var release = loans[i].release;
				var li="<li>"+
                       "<a class0='"+loans[i].class0+"' publisher='"+loans[i].publisher+"' isbn='"+isbn+"' title='"+title+"' author='"+author+"' href='#sjxqdt'>"+
                            "<img isbn='"+isbn+"' src='images/default1.jpg'>"+
                            "<h3>"+title+"</h3>"+
                            "<p>"+author+"<span>著</span> </p>"+
                        "</a>"+
                        "<p>"+"%placHolder%"+
                            "<a class='toSingleUdls zhijzj' href='#lijizj_2' gLibcode='"+gLibcode+"' barcode='"+barcode+"'>直接转借</a>"+
                        "</p>"+
                    "</li>";
				var placeHolder = "";
				if(release){
					placHolder = "<a href='#qxfb' gLibcode='"+gLibcode+"' barcode='"+barcode+"' >取消发布</a>"
				}else{
					placHolder = "<a class='toSingleRelease fabuzj' href='#fabzj_2' gLibcode='"+gLibcode+"' barcode='"+barcode+"'>发布转借</a>"
				}
				li = li.replace("%placHolder%",placHolder);
				$("#myLoanUl").append(li);
			}
			coverCover();
			$("a.toSingleRelease").click(function(){
				setReleaseAddress();
				$("#releasePhone").val(mobile);
				currentGlibcode = $(this).attr("gLibcode");
				currentBarcodes = $(this).attr("barcode");
			});
			$("a[href='#qxfb']").click(function(){
				cancleRelease($(this).attr("gLibcode"),$(this).attr("barcode"));
			});
			$("a.toSingleUdls").click(function(){
				generateQrcode($(this).attr("gLibcode"),$(this).attr("barcode"));
			});
			$("#myLoanUl a[href='#sjxqdt']").click(function(){
				loanDetail($(this));
			});
		}
	});
}
function xuanzeshu(id){
	var Xzul = document.getElementById(id);
	var Xzli = Xzul.getElementsByTagName('li');
		for(var i =0 ; i<Xzli.length;i++)
		{
			Xzli[i].onclick=function()
			{
				if(this.className=='cur'){
					this.className='';
				}else{
					this.className='cur';
				}
			};
		}
}
function BatchReleaseLoan(){
	$.ajax({
		url :interfaceMobileUrl+"/myLoan.json?userid="+userid+"&key="+userkey,
		jsonp: "callback",
	    dataType: "jsonp",
	    beforeSend:function(data){
			$("#batchReleaseLoanUl").html("");
			$("#batchReleaseLoanUl").append(getLoadingLi("正在加载中..."));
		},
		error:function(data){
			$("#batchReleaseLoanUl").html("");
			$("#batchReleaseLoanUl").append(getNoneDataLi("网络连接失败..."));
		},
		success:function(data){
			var loans = eval('(' + data + ')');
			loans = loans.list[0]["com.opac.readerHome.domain.Loan"];
			$("#batchReleaseLoanUl").html("");
			if(loans == undefined){
				$("#batchReleaseLoanUl").append(getNoneDataLi("未获取到您借阅的书籍"));
				return ;
			}
			if(loans.length==undefined){
				loans = [loans];
			}
			console.log(loans);
			for(var i = 0;i<loans.length;i++){
				var title = loans[i].title;
				var author = loans[i].author;
				var isbn = loans[i].isbn;
				var gLibcode = loans[i].gLibcode;
				var barcode = loans[i].barcode;
				var release = loans[i].release;
				var returnDate = loans[i].returnDate["$"].substring(0,11);
				if(!release){
					var li = "<li gLibcode='"+gLibcode+"' barcode='"+barcode+"'><a href='#'> <img isbn="+isbn+" src='images/default1.jpg'>"+
					"<h3>"+title+"</h3>"+
					"<p>"+author+
					"</p>"+
					"<p>"+
						"<span>"+returnDate+"</span><span>应还</span>"+
					"</p>"+
					"</a></li>";
					$("#batchReleaseLoanUl").append(li);
				}
			}
			if($("#batchReleaseLoanUl").html()==""){
				$("#batchReleaseLoanUl").append(getNoneDataLi("您的书籍都已经发布过转借了"));
				return ;
			}
			coverCover();
			xuanzeshu('batchReleaseLoanUl');//选中发布书籍
		}
	});
}
function BatchUdlsLoan(){
	$.ajax({
		url :interfaceMobileUrl+"/myLoan.json?userid="+userid+"&key="+userkey,
		jsonp: "callback",
		dataType: "jsonp",
		beforeSend:function(data){
			$("#batchUdlsLoanUl").html("");
			$("#batchUdlsLoanUl").append(getLoadingLi("正在加载中..."));
		},
		error:function(data){
			$("#batchUdlsLoanUl").html("");
			$("#batchUdlsLoanUl").append(getNoneDataLi("网络连接失败..."));
		},
		success:function(data){
			var loans = eval('(' + data + ')');
			loans = loans.list[0]["com.opac.readerHome.domain.Loan"];
			$("#batchUdlsLoanUl").html("");
			if(loans == undefined){
				$("#batchUdlsLoanUl").append(getNoneDataLi("未获取到您借阅的书籍"));
				return ;
			}
			if(loans.length==undefined){
				loans = [loans];
			}
			for(var i = 0;i<loans.length;i++){
				var title = loans[i].title;
				var author = loans[i].author;
				var isbn = loans[i].isbn;
				var gLibcode = loans[i].gLibcode;
				var barcode = loans[i].barcode;
				var release = loans[i].release;
				var returnDate = loans[i].returnDate["$"].substring(0,11);
				var li = "<li gLibcode='"+gLibcode+"' barcode='"+barcode+"'><a href='#'> <img isbn="+isbn+" src='images/default1.jpg'>"+
				"<h3>"+title+"</h3>"+
				"<p>"+author+
				"</p>"+
				"<p>"+
				"<span>"+returnDate+"</span><span>应还</span>"+
				"</p>"+
				"</a></li>";
				$("#batchUdlsLoanUl").append(li);
			}
			coverCover();
			xuanzeshu('batchUdlsLoanUl');//选中发布书籍
		}
	});
}
$(function(){
	$("a[href='#me_shu']").click(function(){
		if(userid ==null){
			xfAlert("请先登录");
			$.ui.loadContent("#denglu",false,false,"up");
			return false;
		}
		if(!libtied ){
			xfAlert("请先绑定读者证");
			$.ui.loadContent("#bdduzz",false,false,"up");
			return false;
		}
		toMyLoan(userid);
	});
	$("a[href='#fabzj']").click(function(){
		if(userid ==null){
			xfAlert("请先登录");
			$.ui.loadContent("#denglu",false,false,"up");
			return false;
		}
		if(!libtied ){
			xfAlert("请先绑定读者证");
			$.ui.loadContent("#bdduzz",false,false,"up");
			return false;
		}
		BatchReleaseLoan();
	});
	$("a[href='#lijizj']").click(function(){
		if(userid ==null){
			xfAlert("请先登录");
			$.ui.loadContent("#denglu",false,false,"up");
			return false;
		}
		if(!libtied ){
			xfAlert("请先绑定读者证");
			$.ui.loadContent("#bdduzz",false,false,"up");
			return false;
		}
		BatchUdlsLoan();
	});
});
